import Vue from 'vue'
import App from './App'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import store from './store'
import {initMenu} from "./utils/utils";
import "./utils/filters";
import router from './routes'
import NProgress from 'nprogress' // progress bar
import 'nprogress/nprogress.css'// progress bar style
import 'font-awesome/css/font-awesome.min.css'

Vue.use(ElementUI)

import VueQuillEditor  from 'vue-quill-editor'
import 'quill/dist/quill.core.css'
import 'quill/dist/quill.snow.css'
import 'quill/dist/quill.bubble.css'
Vue.use(VueQuillEditor);


NProgress.configure({ showSpinner: false });

router.beforeEach((to, from, next) => {
  NProgress.start();
  if (to.path == '/login') {
    sessionStorage.removeItem('user');
  }
  let user = JSON.parse(sessionStorage.getItem('user'));
  if (!user && to.path != '/login') {
    next({ path: '/login' })
  } else {
    if(user){
      initMenu(router,store)
    }
    next();
  }
})

router.afterEach(transition => {
  NProgress.done();
});


Vue.prototype.imageService = 'http://127.0.0.1:9880'

new Vue({
  el: '#app',
  template: '<App/>',
  router,
  store,
  components: { App }
})

